﻿<Page x:Class="Wokhan.WindowsFirewallNotifier.Console.UI.Pages.AdapterInfo"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:Wokhan.WindowsFirewallNotifier.Console.UI.Pages"
      xmlns:Converters="clr-namespace:Wokhan.WindowsFirewallNotifier.Console.Helpers.BindingConverters"
      mc:Ignorable="d" 
      d:DesignHeight="600" d:DesignWidth="600"
      Title="AdapterInfo"
      xmlns:dummydata="clr-namespace:Wokhan.WindowsFirewallNotifier.Console.Helpers.DummyData"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Page.Resources>
        <Converters:SecondsToDateTimeConverter x:Key="secondsConverter" />
    </Page.Resources>
    <DockPanel>
        <Border Style="{StaticResource ToolBarPanel}">
            <Grid>
                <WrapPanel HorizontalAlignment="Left">
                    <ToggleButton IsChecked="{Binding IsTrackingEnabled}">
                        <Grid>
                            <Path HorizontalAlignment="Left" Width="10" Stretch="Uniform" Fill="Green">
                                <Path.Style>
                                    <Style TargetType="Path">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsTrackingEnabled, FallbackValue=True}" Value="True">
                                                <Setter Property="Data" Value="{StaticResource Image_Stop}" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding IsTrackingEnabled}" Value="False">
                                                <Setter Property="Data" Value="{StaticResource Image_Start}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Path.Style>
                            </Path>
                            <Label Margin="15,0,0,0" Content="Auto-refresh" />
                        </Grid>
                    </ToggleButton>
                </WrapPanel>
                <WrapPanel HorizontalAlignment="Right">
                    <Border BorderBrush="White" Background="White" BorderThickness="0" CornerRadius="8" Padding="5,2" Margin="0,0,5,0">
                        <WrapPanel>
                            <Path Fill="#FFA2A2FF" Data="{StaticResource Image_UpdateRate}"/>
                            <Label Margin="4,0" Content="Update rate:" />
                            <ComboBox IsEditable="False" Width="70" ItemsSource="{Binding Intervals, StringFormat='\{0\}s'}" SelectedValue="{Binding Interval}" />
                        </WrapPanel>
                    </Border>
                    <ToggleButton x:Name="btnHelp">
                        <Path Fill="Chocolate" Data="{StaticResource Image_Help}"/>
                    </ToggleButton>
                </WrapPanel>
            </Grid>
        </Border>
        <Grid>
            <ScrollViewer>
                <ItemsControl ItemsSource="{Binding}" DataContext="{Binding AllInterfaces}" d:DataContext="{d:DesignInstance Type=dummydata:AdapterDummy,IsDesignTimeCreatable=True,CreateList=True}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Expander>
                                <Expander.Header>
                                    <Grid Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Expander}}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="Auto" SharedSizeGroup="bandwidthUP" />
                                            <ColumnDefinition Width="Auto" SharedSizeGroup="bandwidthDOWN" />
                                        </Grid.ColumnDefinitions>
                                        <Path HorizontalAlignment="Left" Height="16" Stretch="Uniform" Data="{StaticResource Image_Adapter}">
                                            <Path.Style>
                                                <Style TargetType="Path">
                                                    <Setter Property="Fill" Value="Red" />
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding Information.OperationalStatus}" Value="Up">
                                                            <Setter Property="Fill" Value="Green" />
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Path.Style>
                                        </Path>
                                        <TextBlock Margin="20,0,0,0" Text="{Binding Information.Name}" />
                                        <WrapPanel HorizontalAlignment="Left" Grid.Column="1" Margin="0,0,10,0">
                                            <Path Margin="0,0,5,0" Height="16" Stretch="Uniform" Fill="Red" Data="{StaticResource Image_DataUp}"/>
                                            <TextBlock Text="{Binding FormattedBytesSent}" Margin="0,0,10,0" />
                                        </WrapPanel>
                                        <WrapPanel HorizontalAlignment="Left" Grid.Column="2" Margin="0,0,40,0">
                                            <Path Margin="0,0,5,0" Height="16" Stretch="Uniform" Fill="Green" Data="{StaticResource Image_DataDown}"/>
                                            <TextBlock Text="{Binding FormattedBytesReceived}" />
                                        </WrapPanel>
                                    </Grid>
                                </Expander.Header>
                                <StackPanel>
                                    <Grid>
                                        <Grid.Resources>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="Margin" Value="4" />
                                                <Style.Triggers>
                                                    <Trigger Property="Grid.Column" Value="0">
                                                        <Setter Property="FontWeight" Value="Bold" />
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Grid.Resources>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <TextBlock Text="Description" />
                                        <TextBlock Grid.Column="1" Text="{Binding Information.Description}" />
                                        <TextBlock Grid.Row="1" Text="Interface type" />
                                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Information.NetworkInterfaceType}" />
                                        <TextBlock Grid.Row="2" Text="Speed" />
                                        <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Information.Speed}" />
                                        <TextBlock Grid.Row="3" Text="MAC address" />
                                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding MAC}" />
                                    </Grid>
                                    <Label FontWeight="Bold" Content="IP addresses" />
                                    <DataGrid GridLinesVisibility="None" AutoGenerateColumns="False" BorderThickness="0" HeadersVisibility="Column" ColumnWidth="*" IsReadOnly="True" ItemsSource="{Binding Properties.UnicastAddresses,Mode=OneWay}">
                                        <DataGrid.CellStyle>
                                            <Style TargetType="DataGridCell">
                                                <Setter Property="VerticalAlignment" Value="Center" />
                                                <Setter Property="Margin" Value="5" />
                                            </Style>
                                        </DataGrid.CellStyle>
                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="Address" Binding="{Binding Address,Mode=OneWay}" />
                                            <DataGridTextColumn Header="Preferred lifetime" Binding="{Binding AddressPreferredLifetime,Mode=OneWay,Converter={StaticResource secondsConverter}}" />
                                            <DataGridTextColumn Header="Valid lifetime" Binding="{Binding AddressValidLifetime,Mode=OneWay,Converter={StaticResource secondsConverter}}" />
                                            <DataGridTextColumn Header="DHCP lease" Binding="{Binding DhcpLeaseLifetime,Mode=OneWay,Converter={StaticResource secondsConverter}}" />
                                        </DataGrid.Columns>
                                    </DataGrid>
                                    <Label FontWeight="Bold" Content="Detailed statistics" />
                                    <Grid>
                                        <Grid.Resources>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="Margin" Value="4" />
                                            </Style>
                                        </Grid.Resources>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <Label HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content="Incoming" Grid.ColumnSpan="2" />
                                        <TextBlock Grid.Row="1" Text="Non-unicast packets" />
                                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Statistics.NonUnicastPacketsReceived}" />
                                        <TextBlock Grid.Row="2" Text="Unicast packets" />
                                        <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Statistics.UnicastPacketsReceived}" />
                                        <TextBlock Grid.Row="3" Text="Discarded packets" />
                                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding Statistics.IncomingPacketsDiscarded}" />
                                        <TextBlock Grid.Row="4" Text="Erroneous packets" />
                                        <TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding Statistics.IncomingPacketsWithErrors}" />
                                        <Label Grid.Column="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content="Outgoing" Grid.ColumnSpan="2" />
                                        <TextBlock Grid.Row="1" Grid.Column="2" Text="Non-unicast packets" />
                                        <TextBlock Grid.Row="1" Grid.Column="3" Text="{Binding Statistics.NonUnicastPacketsSent}" />
                                        <TextBlock Grid.Row="2" Grid.Column="2" Text="Unicast packets" />
                                        <TextBlock Grid.Row="2" Grid.Column="3" Text="{Binding Statistics.UnicastPacketsSent}" />
                                        <TextBlock Grid.Row="3" Grid.Column="2" Text="Discarded packets" />
                                        <TextBlock Grid.Row="3" Grid.Column="3" Text="{Binding Statistics.OutgoingPacketsDiscarded}" />
                                        <TextBlock Grid.Row="4" Grid.Column="2" Text="Erroneous packets" />
                                        <TextBlock Grid.Row="4" Grid.Column="3" Text="{Binding Statistics.OutgoingPacketsWithErrors}" />
                                    </Grid>

                                </StackPanel>
                            </Expander>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
            <Border Style="{StaticResource InfoBlock}">
                <TextBlock>The Adapter information page displays extended information about all adapters on this computer, including virtual devices or interfaces.</TextBlock>
            </Border>
        </Grid>
    </DockPanel>
</Page>
